﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

using Plugin;
using StandardFramework;

namespace StandardLibrary
{
    [ClassAttribute("Timer", "Plugin.Media.clock.ico")]
    class TimerComponentData : BaseComponent
    {
        public delegate void ElapsedHandler(object sender, EventArgs args);

        [EventAttribute("Elapsed", "Plugin.Media.lightning.ico")]
        public event ElapsedHandler Elapsed;

        public void OnElapsed()
        {
            if (Elapsed != null)
            {
                Elapsed(this, null);
            }
        }

        private Timer _timer;

        public TimerComponentData()
        {
            _timer = new Timer(1000);
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
            //Name = "Timer " + BaseComponent.NumberOfComponents;
        }

        public TimerComponentData(double interval)
        {
            _timer = new Timer(interval);
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
        }

        void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            OnElapsed();
        }
    }
}
